<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BGroupMember
 *
 * @author I062261
 */
class BGroupMember extends BEntity {

    //put your code here
    public $groupId = null;
    public $memberId = null;
    public $relationshipId = null;
    public $groupClass = null;
    private $mClass = null;

    //to load obj, should provide id and groupclass args
    public function load($data = NULL) {

        if (is_string($data))
            $this->groupClass = $data;

        if (isset($data['groupClass']))
            $this->groupClass = $data['groupClass'];

        if (isset($data['id']))
            $this->id = $data['id'];

        if ($this->groupClass != NULL) {
            $this->mClass = $mClass = preg_replace("/^B/", "BM", $this->groupClass) . 'Member';
        }

        if ($this->mClass != NULL && $this->id != NULL) {
            $mObj = $mClass::model()->findByPk($this->id);
            $this->name = $mObj->name;
            $this->groupId = $mObj->group_id;
            $this->memberId = $mObj->member_id;
            $this->relationshipId = $mObj->relationship_id;
            $this->spaceId = $mObj->space_id;
            $this->appId = $mObj->app_id;
            $this->status = $mObj->status;
            $this->data = unserialize($mObj->data);
        }
    }

    public static function find($context) {
      
        $attributes = array();

        if (isset($context['groupClass']))
            $attributes['group_class'] = $context['groupClass'];
        else {
            return FALSE;
        }

        if (isset($context['groupId']))
            $attributes['group_id'] = $context['groupId'];

        if (isset($context['memberId']))
            $attributes['member_id'] = $context['memberId'];

        if (isset($context['spaceId']))
            $attributes['space_id'] = $context['spaceId'];

        if (isset($context['appId']))
            $attributes['app_id'] = $context['appId'];

        if (isset($context['relationshipId']))
            $attributes['relationship_id'] = $context['relationshipId'];

        if (isset($context['status']))
            $attributes['status'] = $context['status'];

        $mClass = preg_replace("/^B/", "BM", $attributes['group_class']) . 'Member';

        if ($attributes != NULL)
            return $mClass::model()->findByAttributes($attributes);

        return FALSE;
    }

}

?>
